package com.meta.act.app.domain.tenant;


//import com.metafnt.platform.exception.PlatformErrorCode;
//import com.metafnt.tenant.common.FileTypeEnum;
//import com.meta.framework.act.tenant.entity.TenantFile;
//import com.meta.framework.act.tenant.reqTenantCreateCmd;
import com.meta.framework.exception.PlatformErrorCode;
import com.meta.act.app.tenant.common.FileTypeEnum;
import com.meta.act.app.tenant.entity.TenantFile;
import com.meta.act.app.tenant.req.TenantCreateCmd;
import lombok.Data;
import org.junit.Assert;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/*/**
* @Description:
* @Param:
* @return:
* @Author: simon.Zhang
* @Date: 2020/11/5
*/
@Data
//@Builder
public class TenantFileDo extends TenantFile {

	/*/**
	* @Description:
	* @Param: [cmd, labelId] 
	* @return: com.metafnt.tenant.domain.tenant.TenantDo
	* @Author: simon.Zhang 
	* @Date: 2020/11/5 
	*/ 
	public static List<TenantFileDo> of(TenantCreateCmd cmd, Long tenantId, Integer fileType){

		Assert.assertNotNull(PlatformErrorCode.PARAM_NOT_NULL.getErrorMsg(), cmd.getName());
		Assert.assertNotNull(PlatformErrorCode.PARAM_NOT_NULL.getErrorMsg(), cmd.getFullName());
		Assert.assertNotNull(PlatformErrorCode.PARAM_NOT_NULL.getErrorMsg(), tenantId);
		List<TenantFileDo> list = new ArrayList<>();
		if(FileTypeEnum.TAX_FILE.getCode() == fileType && !CollectionUtils.isEmpty(cmd.getTaxFiles())){
			cmd.getTaxFiles().stream().forEach(x->{
				TenantFileDo fileDo = x.transform(TenantFileDo.class);
				fileDo.setTenantId(tenantId);
				list.add(fileDo);
			});
		}else if (FileTypeEnum.CREDIT_FILE.getCode() == fileType && !CollectionUtils.isEmpty(cmd.getCreditFiles())){
			cmd.getCreditFiles().stream().forEach(x->{
				TenantFileDo fileDo = x.transform(TenantFileDo.class);
				fileDo.setTenantId(tenantId);
				list.add(fileDo);
			});
		}
		return list;
	}
}
